// 级联组件
<template>
  <el-cascader
    :value="value"
    :options="options"
    :props="props"
    size="mini"
    @change="handleChange"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { zhuanghua } from '@/utils'
export default {
  props: {
    value: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      options: [],
      props: {
        label: 'name', // 要展示的字段
        value: 'id'// 要储存的字段
      }
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      this.options = zhuanghua(await getDepartment(), 0)
    },
    handleChange(list) {
      if (list.length > 0) {
        this.$emit('input', list[list.length - 1])
      }
    }
  }
}
</script>

<style>

</style>
